<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Taobao_url_process {//这个类库用于对url符合淘宝规范做处理

    var $CI;
    var $appsetingarray;

    public function __construct() {
        $this->CI = & get_instance();
        $this->CI->load->helper('url');
        $this->CI->config->load('topapiconfig');
        $this->appsetingarray = $this->CI->config->item('tobaokeapi'); //new_app
    }

    function get_url_host($url) {//获取url主地址
        $url_array = parse_url($url);
        return $url_array["host"];
    }

    function get_urlquery_seg($url) {//获取url的query地址
        $url_array = parse_url($url);
        return $url_array["query"];
    }

    function get_urlpath_seg($url) {//获取url的path地址
        $url_array = parse_url($url);
        return $url_array["path"];
    }

    function get_url_itemid($url_query) {//获取url的itmeid地址
        parse_str($url_query, $myArray);
        print_r($myArray);
        echo $myArray["id"];
        // $url_query_array = explode("&", $url_query);
        // print_r($url_query_array);
    }

    function get_url_root($url) {//判断url是否属于淘宝系
        $hosturl = $this->get_url_host($url);
        $CI = & get_instance();
        $CI->config->load('sysetting', TRUE);
        $characters_array = $CI->config->item('host_url'); //获取配置数组
        $istaobao_url = stristr($hosturl, $characters_array["taobao_charact"]);
        $istianmao_url = stristr($hosturl, $characters_array["tianmao_charact"]);
        if ($istaobao_url || $istianmao_url) {
            echo "符合淘宝系列网址命名规则";
            echo $path =$this->get_urlpath_seg($url);
            if ($path == "/item.htm") {
                $query = $this->get_urlquery_seg($url);
                $this->get_url_itemid($query);
            } else {
                echo "应该为淘宝相关活动页面，读取数据库中店铺类型字段生成淘宝店铺
                url";
            }
        } else {
            echo "非淘宝系列网址";
        }
    }

}

/* End of file Someclass.php */